package com.zsyh.jiujiu.fragment.vipFragment;

import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zyh.toolslib.base.BaseFragment;
import com.example.zyh.toolslib.utils.SPUtils;
import com.google.gson.Gson;
import com.lwb.retrofit.RetrofitTask;
import com.zsyh.jiujiu.Api;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.bean.MessageOrderBean;
import com.zsyh.jiujiu.bean.MyInfoBeeean;
import com.zsyh.jiujiu.bean.TaoCanBean;
import com.zsyh.jiujiu.bean.ZhuCeBeaen;
import com.zsyh.jiujiu.net.MyFragementObserver;
import com.zsyh.jiujiu.utils.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class ZhuceFragment extends BaseFragment {
    @BindView(R.id.dengji)
    TextView dengji;
    @BindView(R.id.re_dengji)
    RelativeLayout reDengji;
    @BindView(R.id.tv_dengji)
    TextView tvDengji;
    @BindView(R.id.rvlist)
    RecyclerView rvlist;
    @BindView(R.id.cishu)
    TextView cishu;

    private BaseQuickAdapter<ZhuCeBeaen, BaseViewHolder> mAdapter;
    List<ZhuCeBeaen> list = new ArrayList<>();

    @Override
    protected int initLayout() {
        return R.layout.fragment_zhuce;
    }

    @Override
    protected void initView(View rootView) {

    }

    @Override
    protected void initData() {
        ZhuCeBeaen one=new ZhuCeBeaen();
        one.setName("发布产品");
        one.setDesc("免费发布产品");
        one.setImage(R.mipmap.ic_zhuceyi);
        list.add(one);

        ZhuCeBeaen two=new ZhuCeBeaen();
        two.setName("信息匹配");
        two.setDesc("信息推送被动成交");
        two.setImage(R.mipmap.ic_zhuceer);
        list.add(two);

        ZhuCeBeaen three=new ZhuCeBeaen();
        three.setName("联系客户");
        three.setDesc("免费3次联系客户");
        three.setImage(R.mipmap.ic_zhucesan);
        list.add(three);

        ZhuCeBeaen four=new ZhuCeBeaen();
        four.setName("无受限交易");
        four.setDesc("不限制交易额度");
        four.setImage(R.mipmap.ic_zhucesi);
        list.add(four);

        ZhuCeBeaen five=new ZhuCeBeaen();
        five.setName("在线客服");
        five.setDesc("24小时客服服务");
        five.setImage(R.mipmap.ic_zhucewu);
        list.add(five);


        mAdapter=new BaseQuickAdapter<ZhuCeBeaen, BaseViewHolder>(R.layout.item_zhuce,list) {
            @Override
            protected void convert(@NonNull BaseViewHolder helper, ZhuCeBeaen item) {
                helper.setText(R.id.name,item.getName());
                helper.setText(R.id.desc,item.getDesc());
                helper.setImageResource(R.id.imagezhuce,item.getImage());
            }
        };

        rvlist.setLayoutManager(new GridLayoutManager(getActivity(),3));
        rvlist.setAdapter(mAdapter);


    }

    /**
     * getuser
     */
    public void gettUser(String userid) {
        RetrofitTask.getInstance()
                .createApi(Api.class)
                .getUserById(userid)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new MyFragementObserver(getActivity(), false) {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(String JsonStr) {
                        Log.e("Myinfo", JsonStr + "");
                        Gson gson = new Gson();
                        MyInfoBeeean myInfoBeeean = gson.fromJson(JsonStr, MyInfoBeeean.class);
                        if(myInfoBeeean.getData().getLevel().equals("834598172247461888")){
                            dengji.setText("当前等级");
                        }else if(myInfoBeeean.getData().getLevel().equals("834598284730306560")){
                            dengji.setText("注册会员");
                        }else if(myInfoBeeean.getData().getLevel().equals("834598356696174592")){
                            dengji.setText("注册会员");
                        }

                        dengji((String) SPUtils.get(getActivity(), "userid", ""),"834598172247461888");
                    }
                });
    }

    @Override
    public void onResume() {
        super.onResume();
        gettUser((String) SPUtils.get(getActivity(), "userid", ""));
    }

    /**
     * 等级
     */
    public void dengji(String userid,String id){
        RetrofitTask.getInstance()
                .createApi(Api.class)
                .userHonesty(userid,id)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new MyFragementObserver(getActivity(), false) {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(String JsonStr) {
                        Log.e("dengji", JsonStr + "");
                        Gson gson = new Gson();
                        TaoCanBean taoCanBean = gson.fromJson(JsonStr, TaoCanBean.class);
                        cishu.setText("联系对方剩余："+taoCanBean.getData().getViewTimes()+"次");

                    }
                });
    }

}
